<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:t="http://www.pagac.cz/jsf"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
 <h:head></h:head>
 <h:body>
    <ui:composition template="/WEB-INF/templates/template-insystem.xhtml">

        <!-- Toolbar -->
        <ui:define name="toolbar-place">
            <t:toolbar>
                <t:icon iconName="home" action="goHome" label="#{msgs['toolbar.home']}" />
                <t:icon iconName="print" action="printPage" label="#{msgs['toolbar.print']}" />
                <t:separator />
                <t:icon iconName="add" action="customer/create" 
                        label="#{msgs['toolbar.add']}" sideLabel="true" />
                <t:separator />
                <!-- Granularity selection -->
                <t:icon iconName="more" action="more" backingBean="#{customerManager}" label="#{msgs['toolbar.more']}"
                        bean="true" ajaxExecute="@this" ajaxRender="@all" formId="moreNavLink"
                        renderedBean="#{customerManager.paginator}" renderedAction="moreSafe" />
                <t:icon iconName="less" action="less" backingBean="#{customerManager}" label="#{msgs['toolbar.less']}"
                        bean="true" ajaxExecute="@this" ajaxRender="@all" formId="lessNavLink"
                        renderedBean="#{customerManager.paginator}" renderedAction="remainsSomething" />
                <t:separator />
                <!-- AJAX navigation -->
                <t:icon iconName="first" action="first" backingBean="#{customerManager}" label="#{msgs['toolbar.first']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="firstNavLink"
                    renderedBean="#{customerManager.paginator}" renderedAction="hasPreviousPage" />
                <t:icon iconName="prev" action="previous" backingBean="#{customerManager}" label="#{msgs['toolbar.previous']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="prevNavLink"
                    renderedBean="#{customerManager.paginator}" renderedAction="hasPreviousPage" />
                <t:textIcon rendered="#{customerManager.dataModelRecordsCount > 0}">
                    <h:outputFormat value="&nbsp;#{msgs['app.paging.displayInfo']}">
                        <f:param value="#{customerManager.paginator.pageFirstItem + 1}" />
                        <f:param value="#{customerManager.paginator.pageLastItem + 1}" />
                        <f:param value="#{customerManager.paginator.itemsCount}" />
                    </h:outputFormat>
                    <h:outputText value=" (#{msgs['app.paging.page']} #{customerManager.paginator.actualPage + 1}) " />
                </t:textIcon>
                <t:icon iconName="next" action="next" backingBean="#{customerManager}" label="#{msgs['toolbar.next']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="nextNavLink"
                    renderedBean="#{customerManager.paginator}" renderedAction="hasNextPage" />
                <t:icon iconName="last" action="last" backingBean="#{customerManager}" label="#{msgs['toolbar.last']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="lastNavLink"
                    renderedBean="#{customerManager.paginator}" renderedAction="hasNextPage" />
            </t:toolbar>
        </ui:define>

        <!-- Searchbox -->
        <ui:define name="searchbox">
            <t:field fieldName="searchCustomer" label="#{msgs['app.search-box.label']}"
                     backingBean="#{customerManager}" action="searchPattern">
                <t:searchCommand name="do-search" action="search" backingBean="#{customerManager}"
                                 label="#{msgs['app.search-box.do-search']}">
                    <f:ajax execute="@all" render="@all" onevent="showIndicator" />
                </t:searchCommand>

                <t:searchCommand name="cancel-search" action="cancelSearch" backingBean="#{customerManager}"
                             label="#{msgs['app.search-box.cancel-search']}"
                             rendered="#{customerManager}" renderedProp="searchPattern">
                    <f:ajax execute="@all" render="@all" onevent="showIndicator" />
                </t:searchCommand>
            </t:field>
        </ui:define>

        <!-- Title -->
        <ui:define name="content-title">
            <h1>#{msgs["user.customer.list.page-title"]}</h1>
        </ui:define>

        <!-- Content -->
        <ui:define name="content">
            <h:outputStylesheet name="cssTable.css" library="css" />
                <!-- Customer Listing -->
                <h:dataTable id="customerTable"
                             value="#{customerManager.list}"
                             var="customer"
                             styleClass="listing"
                             rowClasses="odd,even"
                             columnClasses="name, companyIds, address, contact, rateType, pricePerRateUnit, actions"
                             rendered="#{customerManager.dataModelRecordsCount != '0'}">
                    <t:column  headerCssStyle="listing-header" entity="${customer}"
                               fieldName="name" backingBean="#{customerManager}"
                               label="#{msgs['user.customer.list.name']}">
                        <h:commandLink action="#{customerManager.detail}">
                            #{customer.name}
                        </h:commandLink>
                    </t:column>
                    <t:column sort="false" fieldName="companyIds"
                              label="#{msgs['user.customer.list.companyIds']}">
                        #{customer.ic} <br />
                        #{customer.dic}
                    </t:column>
                    <t:column sort="false" fieldName="address"
                              label="#{msgs['user.customer.list.address']}">
                        #{customer.address} <br />
                        #{customer.city} <br />
                        #{customer.zipCode}
                    </t:column>
                    <t:column sort="false" fieldName="contact"
                              label="#{msgs['user.customer.list.contact']}">
                        <a href="mailto:#{customer.email}">#{customer.email}</a><br />
                        #{customer.phone}
                    </t:column>
                    <t:column entity="#{customer}" fieldName="rateType"
                              backingBean="#{customerManager}"
                              label="#{msgs['user.customer.list.rateType']}">
                        #{customer.rateType}
                    </t:column>
                    <t:column entity="#{customer}" fieldName="pricePerRateUnit"
                              backingBean="#{customerManager}"
                              label="#{msgs['user.customer.list.pricePerRateUnit']}">
                        #{customer.pricePerRateUnit} #{msgs['app.currency']}
                    </t:column>
                    <t:columnCommand label="#{msgs['user.customer.list.actions']}">
                        &nbsp;<h:commandButton value="#{msgs['user.customer.list.actions.edit']}" action="#{customerManager.edit}" />
                        <h:commandButton value="#{msgs['user.customer.list.actions.remove']}" action="#{customerManager.remove}"
                                         onclick="return confirm('#{msgs['user.customer.list.actions.removeConfirm']}');">
                            <f:ajax execute="@all" render="@all" onevent="showIndicator" />
                        </h:commandButton>
                        <br />
                        <h:commandButton value="#{msgs['user.customer.list.actions.detail']}" action="#{customerManager.detail}" />
                        <h:commandButton value="#{msgs['user.customer.list.actions.newproject']}" action="#{customerManager.createNewProject}" />
                    </t:columnCommand>
                </h:dataTable>

                <c:if test="#{customerManager.dataModelRecordsCount > 0}">
                    <!-- AJAX navigation -->
                    <p class="statusPageInfoBox">
                        <h:commandLink id="prevLink" action="#{customerManager.previous}"
                                        value="&#9668; #{msgs['app.paging.nextLabel']}"
                                        rendered="#{customerManager.paginator.hasPreviousPage}"
                                        styleClass="prevLink">
                            <f:ajax execute="@this" render="@all" onevent="showIndicator" />
                        </h:commandLink>

                        <h:outputFormat value="&nbsp;#{msgs['app.paging.displayInfo']}&nbsp;">
                            <f:param value="#{customerManager.paginator.pageFirstItem + 1}" />
                            <f:param value="#{customerManager.paginator.pageLastItem + 1}" />
                            <f:param value="#{customerManager.paginator.itemsCount}" />
                        </h:outputFormat>

                        &nbsp;&nbsp;&nbsp;

                        <h:outputText value=" #{msgs['app.paging.page']} #{customerManager.paginator.actualPage + 1} " />

                        <h:commandLink id="nextLink" action="#{customerManager.next}"
                                       value="#{msgs['app.paging.nextLabel']} &#9658;"
                                       rendered="#{customerManager.paginator.hasNextPage}"
                                       styleClass="nextLink">
                            <f:ajax execute="@this" render="@all" onevent="showIndicator" />
                        </h:commandLink>
                    </p>

                    <div class="info-messages">
                        <h3>#{msgs['user.generic.legend']}</h3>

                        <ul>
                            <li>#{msgs['user.generic.rateType-h']}</li>
                            <li>#{msgs['user.generic.rateType-p']}</li>
                            <li>#{msgs['user.generic.rateType-t']}</li>
                        </ul>
                    </div>
                </c:if>
           
            <h:outputFormat styleClass="warning-messages-noitems"
                          rendered="#{(customerManager.dataModelRecordsCount == 0) and (customerManager.searchPattern != '')}"
                          value="#{msgs['app.listing.no-search-records']}">
            </h:outputFormat>

            <h:outputFormat styleClass="warning-messages-noitems" value="#{msgs['app.listing.no-records']}"
                 rendered="#{(customerManager.dataModelRecordsCount == 0) and (customerManager.searchPattern == '')}">
            </h:outputFormat>
                
       </ui:define>

    </ui:composition>

</h:body>
</html>
